
local lineSize =2

---------------------------------------------------------------------
local ShopItem =  BaseClass()
function ShopItem:__init(obj)
	
    self.itemObj = obj
	self.name = obj.transform:Find("Name"):GetComponent(typeof(TextMeshProUGUI))
    self.Img=obj.transform:Find("Img"):GetComponent(typeof(Image))
end

function ShopItem:__delete()

	self.item_data = nil
end

function ShopItem:SetItemData(item_data)
	self.item_data = item_data or nil

    if self.item_data == nil then  self.itemObj:SetActive(false) return end
        self.name.text = self.item_data.l_nameId
   self.Img.sprite=CS.UtilsCSharp.LoadAssetData_PNG(item_data.l_nameId)
end

local ShopContain =  BaseClass()
function ShopContain:__init(obj)
	self.shop_contain_list = {}
	for i = 1, lineSize do
		self.shop_contain_list[i] = ShopItem.New(obj.transform:Find(tostring(i)))
	end
end

function ShopContain:__delete()
	for i = 1, lineSize do
		self.shop_contain_list[i]:DeleteMe()
		self.shop_contain_list[i] = nil
	end
end

function ShopContain:InitItems(item_listData, cell_index)
	for i = 1, lineSize do
        local curIndex = cell_index*lineSize+i
        local itemData = curIndex> #item_listData and nil or item_listData[curIndex]
		self.shop_contain_list[i]:SetItemData(itemData)
	end
end




local UILoginView = BaseClass(UIBaseView)



function UILoginView:OnShow()
    UIBaseView.OnShow(self)
    self.contain_cell_list ={}
    self.img=  self.uiObj.transform:Find("Image"):GetComponent(typeof(Image))
     self.textMeshProUGUI=  self.uiObj.transform:Find("Text (TMP)"):GetComponent(typeof(TextMeshProUGUI))
    self.textMeshProUGUI.text = "AAAAAAAAAAAAA"
    self.btn =self.uiObj.transform:Find("Button") 
    local scroll = self.uiObj.transform:Find("Scroll View")
    CS.UtilsCSharp.AddButtonOnClick(self.btn.gameObject,function(go)
             print(go.name)
            scroll.gameObject:SetActive(true)
    end)
    self.close_btn=scroll.transform:Find("Close")
    CS.UtilsCSharp.AddButtonOnClick(self.close_btn.gameObject,function(go)
        print(go.name)
        scroll.gameObject:SetActive(false)
    
    end)
    local list_delegate = self.uiObj.transform:Find("Scroll View"):GetComponent(typeof(ListViewSimpleDelegate))
	list_delegate.NumberOfCellsDel = BindTool.Bind(self.GetNumberOfCells, self)
	list_delegate.CellRefreshDel = BindTool.Bind(self.RefreshCell, self)

    self.data ={
    [1] = { type = 1, l_nameId = 180000, l_descId = 180100 },
    [2] = { type = 2, l_nameId = 180001, l_descId = 180101 },
    [3] = { type = 3, l_nameId = 180002, l_descId = 180102 },
    [4] = { type = 4, l_nameId = 180003, l_descId = 180103 },
    [5] = { type = 5, l_nameId = 180004, l_descId = 180104 },
    [6] = { type = 6, l_nameId = 180005, l_descId = 180105 },
    [7] = { type = 7, l_nameId = 180006, l_descId = 180106 },
    [8] = { type = 8, l_nameId = 180007, l_descId = 180107 },
    [9] = { type = 9, l_nameId = 180008, l_descId = 180108 },
    [10] = { type = 10, l_nameId = 180009, l_descId = 180109 },
    [11] = { type = 11, l_nameId = 180010, l_descId = 180110 },
    [12] = { type = 12, l_nameId = 180011, l_descId = 180111 },
    [13] = { type = 13, l_nameId = 180012, l_descId = 180112 },
    [14] = { type = 14, l_nameId = 180013, l_descId = 180113 },
    [15] = { type = 15, l_nameId = 180014, l_descId = 180114 },
    [16] = { type = 16, l_nameId = 180015, l_descId = 180115 },
    [17] = { type = 17, l_nameId = 180016, l_descId = 180116 },
    [18] = { type = 18, l_nameId = 180017, l_descId = 180117 },
    [19] = { type = 19, l_nameId = 180018, l_descId = 180118 },
    [20] = { type = 20, l_nameId = 180019, l_descId = 180119 },
    [21] = { type = 21, l_nameId = 180020, l_descId = 180120 },
    [22] = { type = 28, l_nameId = 180021, l_descId = 180121 },
    [23] = { type = 29, l_nameId = 180022, l_descId = 180122 },
    [24] = { type = 30, l_nameId = 180023, l_descId = 180123 },
    [25] = { type = 31, l_nameId = 180024, l_descId = 180124 },
    [26] = { type = 51, l_nameId = 180030, l_descId = 180125 },
    [27] = { type = 52, l_nameId = 180030, l_descId = 180126 },
    [28] = { type = 53, l_nameId = 180030, l_descId = 180127 },
    [29] = { type = 54, l_nameId = 180027, l_descId = 180128 },
    [30] = { type = 55, l_nameId = 180027, l_descId = 180129 }
}
end

function UILoginView:GetNumberOfCells()
	return   Mathf.CeilToInt(#self.data/lineSize)
end

function UILoginView:RefreshCell(cell, cell_index)
	local contain_cell = self.contain_cell_list[cell]
	if contain_cell == nil then
		contain_cell = ShopContain.New(cell.gameObject, self)
		self.contain_cell_list[cell] = contain_cell
	end
	contain_cell:InitItems(self.data, cell_index)
end

function UILoginView:OnDisable()
    UIBaseView.OnDisable(self)
end

function UILoginView:__delete()
    self.img= nil
    self.textMeshProUGUI= nil
end

return UILoginView


